<template>
  <div>
    <el-form :model="formInline" label-width="80px">
      <el-form-item label="菜单名称">
        <el-input v-model.trim="formInline.Name" placeholder="菜单名称"></el-input>
      </el-form-item>
      <el-form-item label="菜单地址">
        <el-input v-model="formInline.Url" placeholder="菜单地址"></el-input>
      </el-form-item>
      <el-form-item label="授权码">
        <el-input v-model="formInline.CustomData" placeholder="授权码"></el-input>
      </el-form-item>
      <el-form-item label="菜单图标">
        <el-input v-model="formInline.Icon" placeholder="菜单图标"></el-input>
      </el-form-item>
      <el-form-item label="菜单类名">
        <el-input v-model="formInline.ClassName" placeholder="菜单类名"></el-input>
      </el-form-item>
      <el-form-item label="菜单上级">
        <el-select v-model="formInline.ParentId" clearable placeholder="请选择">
          <el-option
            v-for="item in parentMenuList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="排序">
        <el-input v-model.number="formInline.Sort" placeholder="排序"></el-input>
      </el-form-item>
      <el-form-item class="editdata_button">
        <el-button type="primary" @click="AddSubmit">保存</el-button>
        <el-button type="default" @click="AddCancle">取消</el-button>
        <el-button type="warning" @click="AddClear">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { mixinAddMixed } from "@/mixedObject/addMixed";
export default {
  mixins: [mixinAddMixed],
  data() {
    return {
      //菜单列表 
      parentMenuList:[],
    };
  },
  created() {
    //初始化表单
    this.InitFormInLine();

    //初始化上级菜单
    this.InitParentMenuList();
  },
  methods: {
    //初始化
    InitFormInLine() {
      this.formInline = {
        Name: "",
        Description: "",
        Sort: 0
      };
    },
   //初始化上级菜单数据
   InitParentMenuList(){
        this.$store
        .dispatch("menu/GetMenuInfoList", {PageIndex: 1,PageSize: 99999})
        .then(data => {
            debugger;
            data.listData.forEach(element => {
                this.parentMenuList.push({value:element.id,label:element.name});
            });
        });
   },
    //保存
    AddSubmit() {
      this.$store
        .dispatch("menu/AddEditMenuInfo", this.formInline)
        .then(data => {
          //回调事件
          this.$emit("SuccessReturn", { type: "add", isSelect: true });
        });
    }
  }
};
</script>